import 'package:get/get.dart';
import 'package:honeypotflutter/modules/package/api/packageApi.dart';
import 'package:honeypotflutter/public/public_alert.dart';
import 'package:honeypotflutter/public/public_total.dart';
import '../../model/package_renewal_Info.dart';

class PackageRetentionListLogic extends GetxController {
  PackageRenewalInfo? info;

  /*
  * 获取滞留信息
  * */
  getRenewalInfo(int? deviceId) async {
    if (deviceId == null) {
      HLTotal.total("deviceId 不能为空");
      return;
    }
    try {
      info = await PackageApi.getRenewalInfo(deviceId);
    } catch (error) {}
  }

  /*
  * 续费
  * */
  quickRenewal(int? deviceId) async {
    if (deviceId == null) {
      HLTotal.total("deviceId 不能为空");
      return;
    }
    if (info == null) {
      HLTotal.total("没有要续约的滞留件");
      return;
    }

    if ((info!.count ?? 0) <= 0) {
      HLTotal.total("没有要续约的滞留件");
      return;
    }

    HLAlert.showSureCancelAlert(
        title: "续费",
        message: "您一共有${info?.count ?? 0}包裹需要一键续期，总计收费${info?.totalFee}元，是否确定一键续期",
        sureAction: (bool isOK) {
          if (!isOK) {
            return;
          }
          PackageApi.quickRenewal(deviceId);
        });
  }
}
